<template>
  <!--  封装elementPlus的dialog组件-->
  <el-dialog
      :model-value="props.visible"
      :title="props.title"
      :width="props.width+'px'"
      :before-close="onClose"
      append-to-body
      :close-on-click-modal="false"
      class="sys-dialog"
      :show-close="false"
  >
    <div class="dialog-content" :style="{height:props.height+'px'}">
      <slot name="content"></slot>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="default" @click="onClose" class="cancel-btn">
          <el-icon><CloseBold /></el-icon>
          取消
        </el-button>
        <el-button type="primary" @click="onConfirm" class="confirm-btn">
          <el-icon><Select /></el-icon>
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { CloseBold, Select } from "@element-plus/icons-vue";

//定义参数类型
interface DialogProps {
  title: string,
  visible: boolean,
  width: number,
  height: number
}

//接收父组件传递的数据
const props = withDefaults(defineProps<DialogProps>(), {
  title: '标题',
  visible: false,
  width: 630,
  height: 280
})
//注册事件
const emit = defineEmits(['onCLose', 'onConfirm'])
//关闭弹框
const onClose = () => {
  emit('onCLose')
}
//确定弹框
const onConfirm = () => {
  emit('onConfirm')
}
</script>

<style>
/* 移除所有可能的 16px padding */
.sys-dialog .el-overlay {
  background-color: rgba(0, 0, 0, 0.5) !important;
  padding: 0 !important;
  margin: 0 !important;
  border-radius: 20px!important;
}

.sys-dialog .el-overlay .el-overlay-dialog {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 !important;
}

.sys-dialog .el-dialog {
  border-radius: 12px !important;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
  border: 1px solid #e4e7ed !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
  width: v-bind('props.width + "px"') !important;
}

.sys-dialog .el-dialog__header {
  background: linear-gradient(135deg, rgba(243, 121, 121, 0.63) 0%, rgb(115, 9, 120) 100%) !important;
  margin: 0 !important;
  padding: 16px 24px !important;
  border-bottom: none !important;
}

.sys-dialog .el-dialog__title {
  color: white !important;
  font-size: 18px !important;
  font-weight: 600 !important;
  letter-spacing: 0.5px !important;
  margin: 0 !important;
  padding: 0 !important;
}

.sys-dialog .el-dialog__body {
  padding: 0 !important;
  margin: 0 !important;
  background: #fafbfc !important;
}

.sys-dialog .dialog-content {
  padding: 24px !important;
  background: #fafbfc !important;
  overflow: auto !important;
  margin: 0 !important;
  height: v-bind('props.height + "px"') !important;
  box-sizing: border-box !important;
}

.sys-dialog .el-dialog__footer {
  background: #f8f9fa !important;
  padding: 16px 24px !important;
  border-top: 1px solid #e9ecef !important;
  margin: 0 !important;
}

/* 按钮样式 */
.dialog-footer {
  display: flex !important;
  justify-content: flex-end !important;
  gap: 12px !important;
  margin: 0 !important;
  padding: 0 !important;
}

.cancel-btn {
  background: #f8f9fa !important;
  border: 1px solid #dee2e6 !important;
  color: #6c757d !important;
  padding: 10px 20px !important;
  border-radius: 8px !important;
  font-weight: 500 !important;
  transition: all 0.3s ease !important;
  margin: 0 !important;
}

.cancel-btn:hover {
  background: #e9ecef !important;
  border-color: #adb5bd !important;
  color: #495057 !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(108, 117, 125, 0.2) !important;
}

.confirm-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  border: none !important;
  color: white !important;
  padding: 10px 24px !important;
  border-radius: 8px !important;
  font-weight: 500 !important;
  transition: all 0.3s ease !important;
  margin: 0 !important;
}

.confirm-btn:hover {
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4) !important;
}

/* 滚动条样式 */
.dialog-content::-webkit-scrollbar {
  width: 6px !important;
}

.dialog-content::-webkit-scrollbar-track {
  background: #f1f1f1 !important;
  border-radius: 3px !important;
}

.dialog-content::-webkit-scrollbar-thumb {
  background: #c1c1c1 !important;
  border-radius: 3px !important;
}

.dialog-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8 !important;
}

/* 动画效果 */
.sys-dialog .el-dialog {
  animation: dialogSlideIn 0.3s ease !important;
}

@keyframes dialogSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 特别针对 Element Plus 的默认 padding */
.el-dialog__wrapper {
  padding: 0 !important;
}

.el-overlay-dialog {
  padding: 0 !important;
}

/* 如果还有 padding，可能是这个选择器 */
div[class*="el-dialog"] {
  padding: 0 !important;
}

/* 确保所有层级的元素都没有 padding */
.sys-dialog * {
  box-sizing: border-box !important;
}
</style>